﻿using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;

namespace FwProject.EFCoreAttribut
{
    /// <summary>
    /// 用于modelBuilder全局设置自定义精度属性
    /// </summary>
    public class DecimalPrecisionAttributeConvention : PropertyAttributeConvention<DecimalPrecisionAttribute>
    {
      
        public override InternalPropertyBuilder Apply([NotNull] InternalPropertyBuilder propertyBuilder, [NotNull] DecimalPrecisionAttribute attribute, [NotNull] MemberInfo clrMember)
        {
            if (propertyBuilder.Metadata.ClrType == typeof(decimal))
                propertyBuilder.HasPrecision(attribute.Precision, attribute.Scale);
            return propertyBuilder;
        }
    }
}
